package com.desay.pangoo.itmt.controller;

import com.desay.pangoo.common.lite.lang.web.CommonResponse;
import com.desay.pangoo.itmt.service.StatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 数据集
 *
 * @author uidq1163
 */
@RestController
@Api(tags = "ITMT 数据统计")
@RequestMapping(value = "/statistics")
@Validated
public class StatisticsController {

	@Autowired
	StatisticsService statisticsService;

	@GetMapping(value = "priorities")
	@ApiOperation(value = "各工作组技术优先级状态", notes = "各工作组技术优先级状态")
	public ResponseEntity<Object> getPrioritiesStatistics() {
		return new ResponseEntity<>(CommonResponse.success(statisticsService.getPrioritiesStatistics()), HttpStatus.OK);
	}

	@GetMapping(value = "keyTech")
	@ApiOperation(value = "关键技术：技术状态统计(近5years)", notes = "关键技术技术状态统计:近5年（当前年-1~当前年+3）")
	public ResponseEntity<Object> getKeyTechMaturityStatistics() {
		return new ResponseEntity<>(CommonResponse.success(statisticsService.getKeyTechMaturityStatistics()),
				HttpStatus.OK);
	}

	@GetMapping(value = "coreTech")
	@ApiOperation(value = "核心技术：技术状态统计(近5years)", notes = "核心技术技术状态统计:近5年（当前年-1~当前年+3）")
	public ResponseEntity<Object> getCoreTechMaturityStatistics() {
		return new ResponseEntity<>(CommonResponse.success(statisticsService.getCoreTechMaturityStatistics()),
				HttpStatus.OK);
	}

	@GetMapping(value = "techTotal")
	@ApiOperation(value = "项目统计", notes = "项目统计")
	public ResponseEntity<Object> getTechTotalStatistics() {
		return new ResponseEntity<>(CommonResponse.success(statisticsService.getTechTotalStatistics()), HttpStatus.OK);
	}

	@GetMapping(value = "activities")
	@ApiOperation(value = "各工作组技术开发启动状态", notes = "各工作组技术开发启动状态")
	public ResponseEntity<Object> getTechOnPlanActivitiesStatistics() {
		return new ResponseEntity<>(CommonResponse.success(statisticsService.getTechOnPlanActivitiesStatistics()),
				HttpStatus.OK);
	}

	@GetMapping(value = "allTech")
	@ApiOperation(value = "各工作组技术路线五年计划", notes = "各工作组技术路线五年计划")
	public ResponseEntity<Object> getAllTechStatistics() {
		return new ResponseEntity<>(CommonResponse.success(statisticsService.getAllTechStatistics()), HttpStatus.OK);
	}

	@GetMapping(value = "getCoreList")
	@ApiOperation(value = "核心关键技术数量", notes = "核心关键技术数量")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "startYear", value = "开始年(yyyy)", required = false, dataType = "int", paramType = "query"),
			@ApiImplicitParam(name = "endYear", value = "结束年(yyyy)", required = false, dataType = "int", paramType = "query"), })
	public ResponseEntity<Object> getCoreList(@RequestParam(value = "startYear", required = false) Integer startYear,
			@RequestParam(value = "endYear", required = false) Integer endYear) {
		return new ResponseEntity<>(CommonResponse.success(statisticsService.getList(startYear, endYear)),
				HttpStatus.OK);
	}

	@GetMapping(value = "getCompleteTechList")
	@ApiOperation(value = "近12个月完成开发的技术数量", notes = "近12个月完成开发的技术数量")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "startYearQuarter", value = "开始：年季度202203(yyyyq)", required = false, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "endYearQuarter", value = "结束：年季度202304(yyyyq)", required = false, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "workGroupId", value = "工作組ID", required = false, dataType = "int", paramType = "query")
	})
	public ResponseEntity<Object> getCompleteTechList(
			@RequestParam(value = "startYearQuarter", required = false) String startYearQuarter,
			@RequestParam(value = "endYearQuarter", required = false) String endYearQuarter,
			@RequestParam(value = "workGroupId", required = false) Long workGroupId
	) {
		return new ResponseEntity<>(
				CommonResponse.success(statisticsService.getCompleteTechList(workGroupId,startYearQuarter, endYearQuarter)),
				HttpStatus.OK);
	}
}
